package com.mj.HashMap;

import jdk.nashorn.internal.ir.ReturnNode;

/**
 * @Author: LDeng
 * @Date: 2021-03-11 17:29
 */
public class Person {
    private int age;
    private float height;
    private String name;

    public Person(int age, float height, String name) {
        this.age = age;
        this.height = height;
        this.name = name;
    }

    @Override
    public int hashCode() {
        int ageHashCode = Integer.hashCode(age);
        int heightHashCode= Float.hashCode(height);
        int nameHashCode=(name!=null)?(name.hashCode()):0;
        int hashCode = ageHashCode;
        hashCode = hashCode * 31 + heightHashCode;
        hashCode = hashCode * 31 + nameHashCode;
        return hashCode;
    }

    @Override
    public boolean equals(Object obj) {
        if(this==obj){
            return true;
        }
        if(obj==null ||obj.getClass()!=this.getClass()){
            return false;//传进来的对象为空 或者类型不一样
        }
        //比较成员变量
        Person person=(Person) obj;
        return person.age==age
                && person.height==height
                && ((person.name==null)?(name==null):person.name.equals(name));
    }
}
